home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- public class ImageMap extends Applet implements Runnable {
- Image backgroundImg;
- Image offImage;
- Graphics offGraphic;
- HotArea[] areas;
- HotArea activeArea;
- HotArea downTarget;
- Color bgColor;
- String separator;
- Image enterImage;
- Image downImage;
- String displayString;
- MediaTracker tracker = new MediaTracker(this);
- private int lastMouseX;
- private int lastMouseY;
- private boolean tipOn = false;
- private Thread timerThread;
- private long lastMoveTime;
- private long clearTime;
- private FontMetrics fontInfo;
- Rectangle tipRect;
- Color tipColor;
- Color tipBgColor;
- Font tipFont;
- private long WAIT_TIME;
- private long KEEP_ON_TIME;
- long lastEventTime;
-
- public void init() {
- this.backgroundImg = ((Applet)this).getImage(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("image"));
- this.tracker.addImage(this.backgroundImg, 0);
- String var1 = ((Applet)this).getParameter("bgColor");
- if (var1 == null) {
- this.bgColor = ((Component)this).getBackground();
- } else {
- this.bgColor = this.convertColor(var1);
- }
-
- ((Component)this).setBackground(this.bgColor);
- var1 = ((Applet)this).getParameter("enterImage");
- if (var1 != null && !var1.equals("")) {
- this.enterImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), var1);
- this.tracker.addImage(this.enterImage, 1);
- Object var3 = null;
- }
-
- var1 = ((Applet)this).getParameter("downImage");
- if (var1 != null && !var1.equals("")) {
- this.downImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), var1);
- this.tracker.addImage(this.downImage, 1);
- Object var5 = null;
- }
-
- this.tracker.checkID(1, true);
- }
-
- public void start() {
- this.timerThread = new Thread(this);
- this.timerThread.start();
- this.update(((Component)this).getGraphics());
- }
-
- private void delayedInit() {
- ImageEffect var1 = null;
- ImageEffect var2 = null;
- Vector var4 = new Vector();
- HotArea var5 = null;
- this.offImage = ((Component)this).createImage(((Component)this).size().width * 2, ((Component)this).size().height);
- this.offGraphic = this.offImage.getGraphics();
- this.offGraphic.setColor(this.bgColor);
- if (this.backgroundImg != null) {
- this.offGraphic.drawImage(this.backgroundImg, 0, 0, this.bgColor, this);
- }
-
- this.separator = ((Applet)this).getParameter("separator");
- if (this.separator == null) {
- this.separator = "|";
- }
-
- String var3 = ((Applet)this).getParameter("defaultEnterEffect");
- if (var3 != null && !var3.equals("(none)") && !var3.equals("")) {
- try {
- int var6 = var3.indexOf(",");
- String var7;
- if (var6 > 0) {
- var7 = var3.substring(0, var6);
- } else {
- var7 = var3;
- }
-
- var1 = (ImageEffect)Class.forName(var7.toLowerCase().trim()).newInstance();
- if (var6 > 0) {
- var3 = var3.substring(var6 + 1);
- } else {
- var3 = null;
- }
-
- var1.init(this, var3);
- } catch (Exception var17) {
- System.out.println("error processing defaultEnterEffect: " + var3);
- }
- }
-
- var3 = ((Applet)this).getParameter("defaultDownEffect");
- if (var3 != null && !var3.equals("(none)") && !var3.equals("")) {
- try {
- int var33 = var3.indexOf(",");
- String var35;
- if (var33 > 0) {
- var35 = var3.substring(0, var33);
- } else {
- var35 = var3;
- }
-
- var2 = (ImageEffect)Class.forName(var35.toLowerCase()).newInstance();
- if (var33 > 0) {
- var3 = var3.substring(var33 + 1);
- } else {
- var3 = null;
- }
-
- var2.init(this, var3);
- } catch (Exception var16) {
- System.out.println("error processing defaultDownEffect: " + var3);
- }
- }
-
- int var34 = 0;
-
- while(true) {
- while(true) {
- ++var34;
- var3 = ((Applet)this).getParameter("area" + var34);
- if (var3 == null) {
- this.areas = new HotArea[var4.size()];
- var4.copyInto(this.areas);
- var3 = ((Applet)this).getParameter("toolTips");
- if (var3 != null) {
- StringTokenizer var37 = new StringTokenizer(var3, this.separator);
-
- while(var37.hasMoreTokens()) {
- String var39 = var37.nextToken();
-
- for(int var44 = 0; var44 < this.areas.length; ++var44) {
- if (this.areas[var44].name != null && this.areas[var44].name.equals(var39)) {
- if (var37.hasMoreTokens()) {
- this.areas[var44].tip = var37.nextToken();
- } else {
- System.out.println("Error: no tooltip to go with area " + var39);
- }
- break;
- }
- }
- }
-
- var3 = ((Applet)this).getParameter("tipdelay");
- if (var3 != null) {
- try {
- this.WAIT_TIME = (long)Integer.parseInt(var3);
- } catch (Exception var15) {
- System.out.println("Could not convert " + var3 + " to an integer, using default value");
- }
- }
-
- this.tipFont = ((Component)this).getGraphics().getFont();
- String var40 = this.tipFont.getName();
- int var45 = this.tipFont.getSize();
- int var49 = this.tipFont.getStyle();
- var3 = ((Applet)this).getParameter("tipFont");
- if (var3 != null) {
- var40 = var3;
- }
-
- var3 = ((Applet)this).getParameter("tipSize");
- if (var3 != null) {
- try {
- var45 = Integer.parseInt(var3);
- } catch (Exception var14) {
- System.out.println("Could not convert " + var3 + " to an integer, using default value");
- }
- }
-
- var3 = ((Applet)this).getParameter("tipStyle");
- if (var3 != null) {
- var3 = var3.toLowerCase();
- if (var3.equals("plain")) {
- var49 = 0;
- } else if (var3.equals("bold")) {
- var49 = 1;
- } else if (var3.equals("italic")) {
- var49 = 2;
- } else if (var3.equals("bolditalic")) {
- var49 = 3;
- } else {
- System.out.println("Invalid style '" + var3 + "' - using Plain...");
- var49 = 0;
- }
- }
-
- this.tipFont = new Font(var40, var49, var45);
- var3 = ((Applet)this).getParameter("tipColor");
- if (var3 != null) {
- this.tipColor = this.convertColor(var3);
- }
-
- var3 = ((Applet)this).getParameter("tipBgColor");
- if (var3 != null) {
- this.tipBgColor = this.convertColor(var3);
- }
- }
-
- if ((this.tracker.statusAll(true) & 8) != 0) {
- try {
- this.tracker.waitForAll();
- } catch (Exception var13) {
- }
- }
-
- if (this.tracker.isErrorAny()) {
- System.out.println("Error loading either or both of the enterImage and downImage");
- }
-
- return;
- }
-
- try {
- StringTokenizer var36 = new StringTokenizer(var3, ",");
- String var8 = var36.nextToken();
- var5 = new HotArea();
- var5.name = var8;
- var5.downEffect = var2;
- var5.enterEffect = var1;
- var8 = var36.nextToken();
- if (!var8.equals("rect") && !var8.equals("circle")) {
- if (var8.equals("poly")) {
- var5.type = 3;
-
- try {
- Polygon var41 = new Polygon();
- var5.destination = var36.nextToken();
- var5.targetFrame = var36.nextToken();
- if (var5.destination != null && var5.destination.equals("null")) {
- var5.destination = null;
- }
-
- if (var5.targetFrame != null && var5.targetFrame.equals("null")) {
- var5.targetFrame = null;
- }
-
- StringTokenizer var46 = new StringTokenizer(var36.nextToken(), this.separator);
-
- while(var46.hasMoreTokens()) {
- int var50 = Integer.parseInt(var46.nextToken());
- int var51 = Integer.parseInt(var46.nextToken());
- var41.addPoint(var50, var51);
- }
-
- var5.geometry = var41;
- } catch (Exception var19) {
- System.out.println("Format error, wrong number or type of parameters for polygon hot area");
- System.out.println("Ignoring this hot area:");
- System.out.println(var3);
- continue;
- }
- }
- } else {
- if (var8.equals("circle")) {
- var5.type = 2;
- } else {
- var5.type = 1;
- }
-
- try {
- var5.destination = var36.nextToken();
- var5.targetFrame = var36.nextToken();
- if (var5.destination != null && var5.destination.equals("null")) {
- var5.destination = null;
- }
-
- if (var5.targetFrame != null && var5.targetFrame.equals("null")) {
- var5.targetFrame = null;
- }
-
- int var9 = Integer.parseInt(var36.nextToken());
- int var10 = Integer.parseInt(var36.nextToken());
- int var11;
- int var12;
- if (var36.countTokens() > 1) {
- var11 = Integer.parseInt(var36.nextToken()) - var9;
- var12 = Integer.parseInt(var36.nextToken()) - var10;
- if (var8.equals("circle")) {
- var9 -= var11;
- var10 -= var11;
- var11 *= 2;
- var12 = var11;
- }
- } else {
- var11 = Integer.parseInt(var36.nextToken());
- var12 = var11;
- }
-
- var5.geometry = new Rectangle(var9, var10, var11, var12);
- } catch (Exception var18) {
- System.out.println("Format error, wrong number or type of parameters for the hot area");
- System.out.println("Ignoring this hot area:");
- System.out.println(var3);
- continue;
- }
- }
-
- if (var36.hasMoreTokens()) {
- String var42 = var36.nextToken();
- if (var42.equals("null")) {
- var36.nextToken();
- } else {
- ImageEffect var47 = (ImageEffect)Class.forName(var42.toLowerCase()).newInstance();
- var47.init(this, var36.nextToken());
- var5.enterEffect = var47;
- }
-
- if (var36.hasMoreTokens()) {
- var42 = var36.nextToken();
- if (var42.equals("null")) {
- var36.nextToken();
- } else {
- ImageEffect var48 = (ImageEffect)Class.forName(var42.toLowerCase()).newInstance();
- var48.init(this, var36.nextToken());
- var5.downEffect = var48;
- }
- break;
- }
- }
- } catch (Exception var20) {
- System.out.println("error processing line action" + var34 + ": " + var3);
- break;
- }
- }
-
- var5.theMap = this;
- var4.addElement(var5);
- }
- }
-
- public void setTip(String var1) {
- if (var1 != null) {
- this.displayString = var1;
- this.timerThread.resume();
- if (this.clearTime + this.KEEP_ON_TIME < System.currentTimeMillis()) {
- this.tipOn = false;
- }
-
- }
- }
-
- public void clearTip() {
- if (this.tipRect != null) {
- this.clearTime = System.currentTimeMillis();
- Graphics var1 = this.offImage.getGraphics();
- var1.copyArea(this.tipRect.x + ((Component)this).size().width, this.tipRect.y, this.tipRect.width, this.tipRect.height, -((Component)this).size().width, 0);
- ((Component)this).getGraphics().drawImage(this.offImage, 0, 0, (ImageObserver)null);
- this.tipRect = null;
- } else {
- this.timerThread.suspend();
- }
- }
-
- public void stop() {
- this.timerThread.stop();
- }
-
- public void run() {
- while(true) {
- this.timerThread.suspend();
-
- while(!this.tipOn) {
- long var1 = System.currentTimeMillis();
-
- try {
- Thread.sleep(this.WAIT_TIME);
- } catch (Exception var5) {
- }
-
- if (var1 > this.lastMoveTime) {
- this.tipOn = true;
- }
- }
-
- if (this.displayString != null) {
- Graphics var6 = this.offImage.getGraphics();
- var6.setFont(this.tipFont);
- FontMetrics var2 = var6.getFontMetrics();
- int var3 = var2.stringWidth(this.displayString);
- int var4 = var2.getDescent() + var2.getAscent();
- if (((Component)this).inside(this.lastMouseX, this.lastMouseY + var4 + 25)) {
- if (((Component)this).inside(this.lastMouseX + var3 + 4, this.lastMouseY)) {
- this.tipRect = new Rectangle(this.lastMouseX, this.lastMouseY + 25, var3 + 4, var4);
- } else {
- this.tipRect = new Rectangle(this.lastMouseX - var3 - 4, this.lastMouseY + 25, var3 + 4, var4);
- }
- } else if (((Component)this).inside(this.lastMouseX + var3 + 4, this.lastMouseY)) {
- this.tipRect = new Rectangle(this.lastMouseX, this.lastMouseY - var4 - 10, var3 + 4, var4);
- } else {
- this.tipRect = new Rectangle(this.lastMouseX - var3 - 4, this.lastMouseY - var4 - 10, var3 + 4, var4);
- }
-
- var6.copyArea(this.tipRect.x, this.tipRect.y, this.tipRect.width, this.tipRect.height, ((Component)this).size().width, 0);
- var6.setColor(this.tipBgColor);
- var6.fillRect(this.tipRect.x, this.tipRect.y, this.tipRect.width, this.tipRect.height);
- var6.setColor(this.tipColor);
- var6.drawRect(this.tipRect.x, this.tipRect.y, this.tipRect.width - 1, this.tipRect.height - 1);
- var6.drawString(this.displayString, this.tipRect.x + 2, this.tipRect.y + var2.getAscent());
- var6 = ((Component)this).getGraphics();
- var6.clipRect(this.tipRect.x, this.tipRect.y, this.tipRect.width, this.tipRect.height);
- var6.drawImage(this.offImage, 0, 0, (ImageObserver)null);
- }
- }
- }
-
- public boolean handleEvent(Event var1) {
- if (var1.when >= this.lastEventTime) {
- this.lastEventTime = var1.when;
- return super.handleEvent(var1);
- } else {
- return true;
- }
- }
-
- public boolean mouseMove(Event var1, int var2, int var3) {
- if (this.areas == null) {
- return true;
- } else if (this.lastMouseX == var2 && this.lastMouseY == var3) {
- return true;
- } else {
- this.lastMouseX = var2;
- this.lastMouseY = var3;
- this.lastMoveTime = var1.when;
-
- for(int var4 = 0; var4 < this.areas.length; ++var4) {
- if (this.areas[var4].inside(var2, var3)) {
- this.areas[var4].checkEnter();
- } else {
- this.areas[var4].checkExit();
- }
- }
-
- return true;
- }
- }
-
- public boolean mouseDrag(Event var1, int var2, int var3) {
- return this.mouseMove(var1, var2, var3);
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- if (this.areas == null) {
- return true;
- } else {
- for(int var4 = 0; var4 < this.areas.length; ++var4) {
- if (this.downTarget == this.areas[var4] && this.downTarget.downEffect != null) {
- this.downTarget.downEffect.stop(this.downTarget);
- }
-
- this.areas[var4].checkExit();
- }
-
- return true;
- }
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.activeArea != null && this.activeArea.mouseInside) {
- this.clearTip();
- this.downTarget = this.activeArea;
- if (this.downTarget.downEffect != null) {
- this.downTarget.downEffect.start(this.downTarget, this.offImage.getGraphics());
- ((Component)this).getGraphics().drawImage(this.offImage, 0, 0, (ImageObserver)null);
- }
-
- return true;
- } else {
- return true;
- }
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- if (this.downTarget == this.activeArea && this.activeArea != null) {
- if (this.downTarget.downEffect != null) {
- this.downTarget.downEffect.stop(this.downTarget);
- }
-
- if (this.downTarget.destination == null) {
- this.downTarget = null;
- return true;
- } else {
- try {
- if (this.downTarget.targetFrame == null) {
- ((Applet)this).getAppletContext().showDocument(new URL(((Applet)this).getDocumentBase(), this.downTarget.destination));
- } else {
- ((Applet)this).getAppletContext().showDocument(new URL(((Applet)this).getDocumentBase(), this.downTarget.destination), this.downTarget.targetFrame);
- }
- } catch (MalformedURLException var4) {
- System.out.println("The specified URL is not formatted correctly: " + this.downTarget.destination);
- }
-
- this.downTarget = null;
- return true;
- }
- } else {
- this.downTarget = null;
- return true;
- }
- }
-
- public void update(Graphics var1) {
- if (this.offImage != null) {
- var1.drawImage(this.offImage, 0, 0, this);
- } else {
- var1.drawImage(this.backgroundImg, 0, 0, (ImageObserver)null);
- if (this.tracker.checkID(0, true)) {
- this.delayedInit();
- ((Component)this).repaint();
- } else {
- ((Component)this).repaint(500L);
- }
- }
- }
-
- public void paint(Graphics var1) {
- this.update(var1);
- }
-
- protected Color convertColor(String var1) {
- if (var1 == null) {
- return Color.black;
- } else {
- var1 = var1.toLowerCase().trim();
- if (var1.equals("black")) {
- return Color.black;
- } else if (var1.equals("blue")) {
- return Color.blue;
- } else if (var1.equals("cyan")) {
- return Color.cyan;
- } else if (var1.equals("darkgray")) {
- return Color.darkGray;
- } else if (var1.equals("gray")) {
- return Color.gray;
- } else if (var1.equals("green")) {
- return Color.green;
- } else if (var1.equals("lightgray")) {
- return Color.lightGray;
- } else if (var1.equals("magenta")) {
- return Color.magenta;
- } else if (var1.equals("orange")) {
- return Color.orange;
- } else if (var1.equals("pink")) {
- return Color.pink;
- } else if (var1.equals("red")) {
- return Color.red;
- } else if (var1.equals("white")) {
- return Color.white;
- } else if (var1.equals("yellow")) {
- return Color.yellow;
- } else {
- try {
- return new Color(Integer.parseInt(var1, 16));
- } catch (NumberFormatException var4) {
- String var2 = var1.substring(1);
-
- try {
- return new Color(Integer.parseInt(var2, 16));
- } catch (NumberFormatException var3) {
- System.out.println("Could not parse: '" + var1 + "' into a color, using black");
- return Color.black;
- }
- }
- }
- }
- }
-
- public String getAppletInfo() {
- return "Imagemap 1.0 - Copyright © 1996, Macromedia, Inc.";
- }
-
- public ImageMap() {
- this.tipColor = Color.black;
- this.tipBgColor = Color.white;
- this.WAIT_TIME = 250L;
- this.KEEP_ON_TIME = 250L;
- }
- }
-